/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.site.console.action;

import java.util.Date;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import com.us.usws.model.domain.system.Clz;
import com.us.usws.model.flat.system.DOUser;
import com.us.usws.service.cud.ClzCUDService;
import com.us.usws.service.ro.ClzROService;
import com.us.usws.support.uitls.JSONDataUtil;
import com.us.usws.support.uitls.Order;
import com.us.usws.support.uitls.SiteWebContext;
import com.us.usws.support.uitls.WebContext;

/**
 * Struts2 action
 * @author robot
 */
public class ClzAction extends BasePageSearchAction<Clz> {

	private static final long serialVersionUID = 1L;

	private Clz clz;

	@Inject
	private ClzROService clzROService;

	@Inject
	private ClzCUDService clzCUDService;

	private String uids;

	/**
	 * ajax load the list of Clz
	 */
	public void ajaxLoadClzs() {
		createDataPageUtil();
		dataPageUtil.setOrder(Order.desc("create_date"));
		clzROService.loadSchoolsByPage(dataPageUtil);
		getOut().println(JSONDataUtil.extJsonSupportPage(dataPageUtil.getResult(), dataPageUtil.getRowCount()));
	}

	/**
	 * ajax update Clz
	 */
	public void ajaxUpdateClz() {
		if (clz != null) {
			Date now = new Date(System.currentTimeMillis());
			WebContext wc = new SiteWebContext(getRequest(), getResponse());
			DOUser user = wc.getUser();
			String uid = clz.getUid();
			if (StringUtils.isNotBlank(uid)) {
				clz.setLastUpdByUid(user.getUid());
				clz.setLastUpdDate(now);
				clzCUDService.updateClz(clz);
			} else {
				clz.setCreateByUid(user.getUid());
				clz.setCreateDate(now);
				clzCUDService.addClz(clz);
			}
			getOut().print(true);
		} else {
			getOut().print(false);
		}
	}

	/**
	 * ajax delete user.
	 */
	public void ajaxDeleteClz() {
		clzCUDService.deleteClzMore(uids);
	}

	public void setClz(Clz clz) {
		this.clz = clz;
	}

	public Clz getClz() {
		return clz;
	}

	public String getUids() {
		return uids;
	}

	public void setUids(String uids) {
		this.uids = uids;
	}

}